package com.aidong.service;

/**
 * Created by john on 16-11-2.
 */
import com.aidong.cache.ItemCache;
import com.aidong.dao.wills.BoxRentDao;
import com.aidong.dao.wills.MemberChangeCardDao;
import com.aidong.dao.wills.MemberChangeShopDao;
import com.aidong.dao.wills.MemberContractDao;
import com.aidong.dao.wills.MemberEarnestDao;
import com.aidong.dao.wills.MemberInfoDao;
import com.aidong.dao.wills.MemberStopedCardDao;
import com.aidong.dao.wills.MemberTransferDao;
import com.aidong.dao.wills.PssProductCodeDao;
import com.aidong.dao.wills.PtBespeakDao;
import com.aidong.dao.wills.PtContractDao;
import com.aidong.dao.wills.PtPackageDao;
import com.aidong.dao.wills.PtPackageItemDao;
import com.aidong.dao.wills.SmsListDao;
import com.aidong.dao.wills.SmsTypeDao;
import com.aidong.model.LoginUser;
import com.aidong.model.wills.BoxRent;
import com.aidong.model.wills.MemberChangeCard;
import com.aidong.model.wills.MemberChangeShop;
import com.aidong.model.wills.MemberContract;
import com.aidong.model.wills.MemberEarnest;
import com.aidong.model.wills.MemberInfo;
import com.aidong.model.wills.MemberStopedCard;
import com.aidong.model.wills.MemberTransfer;
import com.aidong.model.wills.PssProductCode;
import com.aidong.model.wills.PtBespeak;
import com.aidong.model.wills.PtContract;
import com.aidong.model.wills.PtPackage;
import com.aidong.model.wills.PtPackageItem;
import com.aidong.model.wills.SmsList;
import com.aidong.model.wills.SmsType;
import com.aidong.service.SmsSendService;
import com.aidong.service.SysUserSession;
import com.aidong.util.FuncUtil;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

@Service
public class SmsListService {
    protected Logger log = Logger.getLogger(this.getClass());
    @Resource
    protected ItemCache cache;
    @Resource
    protected SysUserSession userSession;
    @Resource
    protected SmsTypeDao smsTypeDao;
    @Resource
    protected SmsListDao smsListDao;
    @Resource
    MemberContractDao memberContractDao;
    @Resource
    PtContractDao ptContractDao;
    @Resource
    PtBespeakDao ptBespeakDao;
    @Resource
    MemberInfoDao memberInfoDao;
    @Resource
    MemberEarnestDao memberEarnestDao;
    @Resource
    MemberStopedCardDao memberStopedCardDao;
    @Resource
    MemberTransferDao memberTransferDao;
    @Resource
    MemberChangeShopDao memberChangeShopDao;
    @Resource
    MemberChangeCardDao memberChangeCardDao;
    @Resource
    BoxRentDao boxRentDao;
    @Resource
    PtPackageDao ptPackageDao;
    @Resource
    PtPackageItemDao ptPackageItemDao;
    @Resource
    PssProductCodeDao pssProductCodeDao;
    @Resource
    SmsSendService smsSendService;

    public SmsListService() {
    }

    public boolean sendVerify(String mobile, String verifyCode) {
        SmsType smsType = (SmsType)this.smsTypeDao.getById("91");
        if(smsType != null && smsType.getStatus().intValue() == 1 && smsType.getSmsText() != null && smsType.getSmsText().length() != 0) {
            try {
                String e = smsType.getSmsText().replaceAll("\\{验证码\\}", verifyCode);
                SmsList sms = new SmsList();
                sms.setShopCode(this.getLoginShopCode());
                sms.setMobile(mobile);
                sms.setSmsText(e);
                sms.setSmsType(smsType.getCode());
                sms.setStatus(Integer.valueOf(0));
                sms.setCreateUser(this.getLoginUserCode());
                sms.setCreateTime(new Date());
                sms.setUpdateTime(new Date());
                if(this.smsSendService.sendNow(sms)) {
                    this.smsListDao.add(sms);
                    return true;
                }
            } catch (Exception var6) {
                this.log.error("sendVerify error", var6);
            }

            return false;
        } else {
            return false;
        }
    }

    public boolean addSmsList(String type, int saleId) {
        SmsType smsType = (SmsType)this.smsTypeDao.getById(type);
        if(smsType != null && smsType.getStatus().intValue() == 1 && smsType.getSmsText() != null && smsType.getSmsText().length() != 0) {
            try {
                SmsList e = null;
                if(FuncUtil.strInArray(type, new String[]{"11", "12", "13", "18"})) {
                    e = this.getMemberContractSms(smsType.getSmsText(), saleId);
                } else if(FuncUtil.strInArray(type, new String[]{"51", "52", "53"})) {
                    e = this.getMemberContractGiftCardSms(smsType.getSmsText(), saleId);
                } else if("14".equals(type)) {
                    e = this.getMemberStopedCardSms(smsType.getSmsText(), saleId);
                } else if("15".equals(type)) {
                    e = this.getMemberChangeCardSms(smsType.getSmsText(), saleId);
                } else if("16".equals(type)) {
                    e = this.getMemberChangeShopSms(smsType.getSmsText(), saleId);
                } else if("17".equals(type)) {
                    e = this.getMemberTransferSms(smsType.getSmsText(), saleId);
                } else if("21".equals(type)) {
                    e = this.getPtContractSms(smsType.getSmsText(), saleId);
                } else if("24".equals(type)) {
                    e = this.getPtContractPackageSms(smsType.getSmsText(), saleId);
                } else if(FuncUtil.strInArray(type, new String[]{"22", "23"})) {
                    e = this.getPtBespeakSms(smsType.getSmsText(), saleId);
                } else if("31".equals(type)) {
                    e = this.getBoxRentSms(smsType.getSmsText(), saleId);
                } else if(FuncUtil.strInArray(type, new String[]{"41", "42"})) {
                    e = this.getMemberEarnestSms(smsType.getSmsText(), saleId);
                }

                if(e == null) {
                    return false;
                } else {
                    e.setSmsType(type);
                    e.setStatus(Integer.valueOf(0));
                    e.setCreateUser(this.getLoginUserCode());
                    e.setCreateTime(new Date());
                    e.setUpdateTime(new Date());
                    this.smsListDao.add(e);
                    this.smsSendService.runNow();
                    return true;
                }
            } catch (Exception var5) {
                this.log.error("addSmsList error", var5);
                return false;
            }
        } else {
            return false;
        }
    }

    public SmsList getMemberContractSms(String text, int saleId) {
        MemberContract contract = (MemberContract)this.memberContractDao.getById(Integer.valueOf(saleId));
        if(contract == null) {
            return null;
        } else {
            MemberInfo member = this.memberInfoDao.getById(contract.getMemberCode());
            if(member != null && member.getMobile() != null && member.getMobile().length() != 0) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                DecimalFormat nf = new DecimalFormat("0.##");
                text = text.replaceAll("\\{会员姓名\\}", member.getChName());
                text = text.replaceAll("\\{会员编号\\}", member.getMemberCode());
                text = text.replaceAll("\\{会员卡号\\}", member.getCardCode());
                text = text.replaceAll("\\{会籍开始日期\\}", contract.getBeginTime() == null?"":sdf.format(contract.getBeginTime()));
                text = text.replaceAll("\\{会籍结束日期\\}", contract.getEndTime() == null?"":sdf.format(contract.getEndTime()));
                text = text.replaceAll("\\{会籍卡种\\}", this.cache.getValue("cardType", contract.getCardType()));
                text = text.replaceAll("\\{会籍合同金额\\}", nf.format(contract.getFactPrice()));
                SmsList sms = new SmsList();
                sms.setShopCode(contract.getShopCode());
                sms.setMemberCode(member.getMemberCode());
                sms.setMobile(member.getMobile());
                sms.setSmsText(text);
                return sms;
            } else {
                return null;
            }
        }
    }

    public SmsList getMemberContractGiftCardSms(String text, int saleId) {
        MemberContract contract = (MemberContract)this.memberContractDao.getById(Integer.valueOf(saleId));
        if(contract == null) {
            return null;
        } else {
            MemberInfo member = this.memberInfoDao.getById(contract.getMemberCode());
            if(member != null && member.getMobile() != null && member.getMobile().length() != 0) {
                if(contract.getGiftCardType() != null && contract.getGiftCardCode() != null && contract.getGiftCardAmount() != null) {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    DecimalFormat nf = new DecimalFormat("0.##");
                    text = text.replaceAll("\\{会员姓名\\}", member.getChName());
                    text = text.replaceAll("\\{会员编号\\}", member.getMemberCode());
                    text = text.replaceAll("\\{会员卡号\\}", member.getCardCode());
                    text = text.replaceAll("\\{会籍开始日期\\}", contract.getBeginTime() == null?"":sdf.format(contract.getBeginTime()));
                    text = text.replaceAll("\\{会籍结束日期\\}", contract.getEndTime() == null?"":sdf.format(contract.getEndTime()));
                    text = text.replaceAll("\\{会籍卡种\\}", this.cache.getValue("cardType", contract.getCardType()));
                    text = text.replaceAll("\\{会籍合同金额\\}", nf.format(contract.getFactPrice()));
                    text = text.replaceAll("\\{储值卡名称\\}", this.cache.getValue("giftCardType", contract.getGiftCardType()));
                    text = text.replaceAll("\\{储值卡卡号\\}", contract.getGiftCardCode());
                    text = text.replaceAll("\\{储值卡金额\\}", nf.format(contract.getGiftCardAmount()));
                    SmsList sms = new SmsList();
                    sms.setShopCode(contract.getShopCode());
                    sms.setMemberCode(member.getMemberCode());
                    sms.setMobile(member.getMobile());
                    sms.setSmsText(text);
                    return sms;
                } else {
                    return null;
                }
            } else {
                return null;
            }
        }
    }

    public SmsList getMemberStopedCardSms(String text, int saleId) {
        MemberStopedCard stopedCard = (MemberStopedCard)this.memberStopedCardDao.getById(Integer.valueOf(saleId));
        if(stopedCard == null) {
            return null;
        } else {
            MemberInfo member = this.memberInfoDao.getById(stopedCard.getMemberCode());
            if(member != null && member.getMobile() != null && member.getMobile().length() != 0) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                DecimalFormat nf = new DecimalFormat("0.##");
                text = text.replaceAll("\\{会员姓名\\}", member.getChName());
                text = text.replaceAll("\\{会员编号\\}", member.getMemberCode());
                text = text.replaceAll("\\{会员卡号\\}", member.getCardCode());
                text = text.replaceAll("\\{停卡开始日期\\}", stopedCard.getBeginStopTime() == null?"":sdf.format(stopedCard.getBeginStopTime()));
                text = text.replaceAll("\\{停卡结束日期\\}", stopedCard.getEndStopTime() == null?"":sdf.format(stopedCard.getEndStopTime()));
                text = text.replaceAll("\\{会籍卡种\\}", this.cache.getValue("cardType", stopedCard.getCardType()));
                text = text.replaceAll("\\{停卡手续费\\}", nf.format(stopedCard.getAddFee()));
                SmsList sms = new SmsList();
                sms.setShopCode(stopedCard.getShopCode());
                sms.setMemberCode(member.getMemberCode());
                sms.setMobile(member.getMobile());
                sms.setSmsText(text);
                return sms;
            } else {
                return null;
            }
        }
    }

    public SmsList getMemberChangeCardSms(String text, int saleId) {
        MemberChangeCard changeCard = (MemberChangeCard)this.memberChangeCardDao.getById(Integer.valueOf(saleId));
        if(changeCard == null) {
            return null;
        } else {
            MemberContract contract = this.memberContractDao.getByContractCode(changeCard.getContractCode());
            if(contract == null) {
                return null;
            } else {
                MemberInfo member = this.memberInfoDao.getById(contract.getMemberCode());
                if(member != null && member.getMobile() != null && member.getMobile().length() != 0) {
                    new SimpleDateFormat("yyyy-MM-dd");
                    DecimalFormat nf = new DecimalFormat("0.##");
                    text = text.replaceAll("\\{会员姓名\\}", member.getChName());
                    text = text.replaceAll("\\{会员编号\\}", member.getMemberCode());
                    text = text.replaceAll("\\{会员卡号\\}", member.getCardCode());
                    text = text.replaceAll("\\{补卡新卡号\\}", changeCard.getNewCardCode());
                    text = text.replaceAll("\\{会籍卡种\\}", this.cache.getValue("cardType", contract.getCardType()));
                    text = text.replaceAll("\\{补卡手续费\\}", nf.format(changeCard.getAddFee()));
                    SmsList sms = new SmsList();
                    sms.setShopCode(changeCard.getShopCode());
                    sms.setMemberCode(member.getMemberCode());
                    sms.setMobile(member.getMobile());
                    sms.setSmsText(text);
                    return sms;
                } else {
                    return null;
                }
            }
        }
    }

    public SmsList getMemberChangeShopSms(String text, int saleId) {
        MemberChangeShop changeShop = (MemberChangeShop)this.memberChangeShopDao.getById(Integer.valueOf(saleId));
        if(changeShop == null) {
            return null;
        } else {
            MemberContract contract = this.memberContractDao.getByContractCode(changeShop.getContractCode());
            if(contract == null) {
                return null;
            } else {
                MemberInfo member = this.memberInfoDao.getById(contract.getMemberCode());
                if(member != null && member.getMobile() != null && member.getMobile().length() != 0) {
                    new SimpleDateFormat("yyyy-MM-dd");
                    DecimalFormat nf = new DecimalFormat("0.##");
                    text = text.replaceAll("\\{会员姓名\\}", member.getChName());
                    text = text.replaceAll("\\{会员编号\\}", member.getMemberCode());
                    text = text.replaceAll("\\{会员卡号\\}", member.getCardCode());
                    text = text.replaceAll("\\{转入门店\\}", this.cache.getValue("shopName", changeShop.getNewShopCode()));
                    text = text.replaceAll("\\{会籍卡种\\}", this.cache.getValue("cardType", contract.getCardType()));
                    text = text.replaceAll("\\{转店手续费\\}", nf.format(changeShop.getAddFee()));
                    SmsList sms = new SmsList();
                    sms.setShopCode(changeShop.getShopCode());
                    sms.setMemberCode(member.getMemberCode());
                    sms.setMobile(member.getMobile());
                    sms.setSmsText(text);
                    return sms;
                } else {
                    return null;
                }
            }
        }
    }

    public SmsList getMemberTransferSms(String text, int saleId) {
        MemberTransfer transfer = (MemberTransfer)this.memberTransferDao.getById(Integer.valueOf(saleId));
        if(transfer == null) {
            return null;
        } else {
            MemberContract contract = this.memberContractDao.getByContractCode(transfer.getContractCode());
            if(contract == null) {
                return null;
            } else {
                MemberInfo member = this.memberInfoDao.getById(contract.getMemberCode());
                if(member != null && member.getMobile() != null && member.getMobile().length() != 0) {
                    MemberInfo newMember = this.memberInfoDao.getById(transfer.getNewMemberCode());
                    if(newMember == null) {
                        return null;
                    } else {
                        new SimpleDateFormat("yyyy-MM-dd");
                        DecimalFormat nf = new DecimalFormat("0.##");
                        text = text.replaceAll("\\{会员姓名\\}", member.getChName());
                        text = text.replaceAll("\\{会员编号\\}", member.getMemberCode());
                        text = text.replaceAll("\\{会员卡号\\}", member.getCardCode());
                        text = text.replaceAll("\\{受让人姓名\\}", newMember.getChName());
                        text = text.replaceAll("\\{会籍卡种\\}", this.cache.getValue("cardType", contract.getCardType()));
                        text = text.replaceAll("\\{转让手续费\\}", nf.format(transfer.getAddFee()));
                        SmsList sms = new SmsList();
                        sms.setShopCode(transfer.getShopCode());
                        sms.setMemberCode(member.getMemberCode());
                        sms.setMobile(member.getMobile());
                        sms.setSmsText(text);
                        return sms;
                    }
                } else {
                    return null;
                }
            }
        }
    }

    public SmsList getPtContractSms(String text, int saleId) {
        PtContract contract = (PtContract)this.ptContractDao.getById(Integer.valueOf(saleId));
        if(contract == null) {
            return null;
        } else {
            MemberInfo member = this.memberInfoDao.getById(contract.getMemberCode());
            if(member != null && member.getMobile() != null && member.getMobile().length() != 0) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                DecimalFormat nf = new DecimalFormat("0.##");
                text = text.replaceAll("\\{会员姓名\\}", member.getChName());
                text = text.replaceAll("\\{会员编号\\}", member.getMemberCode());
                text = text.replaceAll("\\{会员卡号\\}", member.getCardCode());
                text = text.replaceAll("\\{私教开始日期\\}", contract.getBeginTime() == null?"":sdf.format(contract.getBeginTime()));
                text = text.replaceAll("\\{私教结束日期\\}", contract.getEndTime() == null?"":sdf.format(contract.getEndTime()));
                text = text.replaceAll("\\{私教课程名称\\}", this.cache.getValue("ptItemName", contract.getPtCode()));
                text = text.replaceAll("\\{私教教练姓名\\}", this.cache.getValue("ptCoachName", contract.getCoachCode()));
                text = text.replaceAll("\\{私教合同金额\\}", nf.format(contract.getFactPrice()));
                text = text.replaceAll("\\{私教合同课时数\\}", nf.format(contract.getQuantity()));
                SmsList sms = new SmsList();
                sms.setShopCode(contract.getShopCode());
                sms.setMemberCode(member.getMemberCode());
                sms.setMobile(member.getMobile());
                sms.setSmsText(text);
                return sms;
            } else {
                return null;
            }
        }
    }

    public SmsList getPtContractPackageSms(String text, int saleId) {
        PtContract contract = (PtContract)this.ptContractDao.getById(Integer.valueOf(saleId));
        if(contract == null) {
            return null;
        } else {
            MemberInfo member = this.memberInfoDao.getById(contract.getMemberCode());
            if(member != null && member.getMobile() != null && member.getMobile().length() != 0) {
                if(contract.getPackageCode() != null && contract.getPackageCode().length() != 0) {
                    PtPackage pkg = (PtPackage)this.ptPackageDao.getById(contract.getPackageCode());
                    if(pkg == null) {
                        return null;
                    } else {
                        List itemList = this.ptPackageItemDao.getPtPackageItemList(pkg.getCode(), "2");
                        StringBuilder sb = new StringBuilder();
                        Iterator sdf = itemList.iterator();

                        while(sdf.hasNext()) {
                            PtPackageItem nf = (PtPackageItem)sdf.next();
                            PssProductCode sms = (PssProductCode)this.pssProductCodeDao.getById(nf.getItemCode());
                            if(sms != null) {
                                if(sb.length() > 0) {
                                    sb.append("、");
                                }

                                String unit = this.cache.getValue("productUnit", sms.getUnit());
                                sb.append(sms.getProductName()).append(nf.getQuantity()).append(unit == null?sms.getUnit():unit);
                            }
                        }

                        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
                        DecimalFormat nf1 = new DecimalFormat("0.##");
                        text = text.replaceAll("\\{会员姓名\\}", member.getChName());
                        text = text.replaceAll("\\{会员编号\\}", member.getMemberCode());
                        text = text.replaceAll("\\{会员卡号\\}", member.getCardCode());
                        text = text.replaceAll("\\{私教开始日期\\}", contract.getBeginTime() == null?"":sdf1.format(contract.getBeginTime()));
                        text = text.replaceAll("\\{私教结束日期\\}", contract.getEndTime() == null?"":sdf1.format(contract.getEndTime()));
                        text = text.replaceAll("\\{私教课程名称\\}", this.cache.getValue("ptItemName", contract.getPtCode()));
                        text = text.replaceAll("\\{私教教练姓名\\}", this.cache.getValue("ptCoachName", contract.getCoachCode()));
                        text = text.replaceAll("\\{私教合同金额\\}", nf1.format(contract.getFactPrice()));
                        text = text.replaceAll("\\{私教合同课时数\\}", nf1.format(contract.getQuantity()));
                        text = text.replaceAll("\\{套餐名称\\}", pkg.getChName());
                        text = text.replaceAll("\\{套餐金额\\}", nf1.format(pkg.getTotalPrice()));
                        text = text.replaceAll("\\{套餐商品\\}", sb.toString());
                        SmsList sms1 = new SmsList();
                        sms1.setShopCode(contract.getShopCode());
                        sms1.setMemberCode(member.getMemberCode());
                        sms1.setMobile(member.getMobile());
                        sms1.setSmsText(text);
                        return sms1;
                    }
                } else {
                    return null;
                }
            } else {
                return null;
            }
        }
    }

    public SmsList getPtBespeakSms(String text, int saleId) {
        PtBespeak bespeak = (PtBespeak)this.ptBespeakDao.getById(Integer.valueOf(saleId));
        if(bespeak == null) {
            return null;
        } else {
            MemberInfo member = this.memberInfoDao.getById(bespeak.getMemberCode());
            if(member != null && member.getMobile() != null && member.getMobile().length() != 0) {
                SimpleDateFormat sdf = new SimpleDateFormat("M月d日 H点mm分");
                new DecimalFormat("0.##");
                text = text.replaceAll("\\{会员姓名\\}", member.getChName());
                text = text.replaceAll("\\{会员编号\\}", member.getMemberCode());
                text = text.replaceAll("\\{会员卡号\\}", member.getCardCode());
                text = text.replaceAll("\\{私教预约时间\\}", bespeak.getClassTime() == null?"":sdf.format(bespeak.getClassTime()));
                text = text.replaceAll("\\{私教核销时间\\}", bespeak.getClearTime() == null?"":sdf.format(bespeak.getClearTime()));
                text = text.replaceAll("\\{私教课程名称\\}", this.cache.getValue("ptItemName", bespeak.getPtCode()));
                text = text.replaceAll("\\{私教教练姓名\\}", this.cache.getValue("ptCoachName", bespeak.getCoachCode()));
                SmsList sms = new SmsList();
                sms.setShopCode(bespeak.getShopCode());
                sms.setMemberCode(member.getMemberCode());
                sms.setMobile(member.getMobile());
                sms.setSmsText(text);
                return sms;
            } else {
                return null;
            }
        }
    }

    public SmsList getBoxRentSms(String text, int saleId) {
        BoxRent rent = (BoxRent)this.boxRentDao.getById(Integer.valueOf(saleId));
        if(rent == null) {
            return null;
        } else {
            MemberInfo member = this.memberInfoDao.getById(rent.getMemberCode());
            if(member != null && member.getMobile() != null && member.getMobile().length() != 0) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                DecimalFormat nf = new DecimalFormat("0.##");
                text = text.replaceAll("\\{会员姓名\\}", member.getChName());
                text = text.replaceAll("\\{会员编号\\}", member.getMemberCode());
                text = text.replaceAll("\\{会员卡号\\}", member.getCardCode());
                text = text.replaceAll("\\{租箱开始日期\\}", rent.getBeginTime() == null?"":sdf.format(rent.getBeginTime()));
                text = text.replaceAll("\\{租箱结束日期\\}", rent.getEndTime() == null?"":sdf.format(rent.getEndTime()));
                text = text.replaceAll("\\{租箱号\\}", rent.getBoxCode());
                text = text.replaceAll("\\{租箱合同金额\\}", nf.format(rent.getFactAmount()));
                SmsList sms = new SmsList();
                sms.setShopCode(rent.getShopCode());
                sms.setMemberCode(member.getMemberCode());
                sms.setMobile(member.getMobile());
                sms.setSmsText(text);
                return sms;
            } else {
                return null;
            }
        }
    }

    public SmsList getMemberEarnestSms(String text, int saleId) {
        MemberEarnest earnest = (MemberEarnest)this.memberEarnestDao.getById(Integer.valueOf(saleId));
        if(earnest != null && earnest.getMobile() != null && earnest.getMobile().length() != 0) {
            new SimpleDateFormat("yyyy-MM-dd");
            DecimalFormat nf = new DecimalFormat("0.##");
            text = text.replaceAll("\\{会员姓名\\}", earnest.getCustName());
            text = text.replaceAll("\\{会员编号\\}", this.nvl(earnest.getMemberCode()));
            text = text.replaceAll("\\{会员卡号\\}", this.nvl(earnest.getCardCode()));
            text = text.replaceAll("\\{定金类型\\}", this.cache.getValue("earnestType", earnest.getEarnestType()));
            text = text.replaceAll("\\{定金金额\\}", nf.format(earnest.getEarnestAmount()));
            text = text.replaceAll("\\{会籍卡种\\}", this.nvl(this.cache.getValue("cardType", earnest.getCardType())));
            text = text.replaceAll("\\{余款金额\\}", earnest.getCardPrice() == null?"":nf.format(earnest.getCardPrice().doubleValue() - earnest.getEarnestAmount().doubleValue()));
            SmsList sms = new SmsList();
            sms.setShopCode(earnest.getShopCode());
            sms.setMemberCode(earnest.getMemberCode());
            sms.setMobile(earnest.getMobile());
            sms.setSmsText(text);
            return sms;
        } else {
            return null;
        }
    }

    protected String getLoginUserCode() {
        LoginUser user = this.userSession.getLoginUser();
        return user != null?user.getUserCode():null;
    }

    protected String getLoginShopCode() {
        LoginUser user = this.userSession.getLoginUser();
        return user != null?user.getShopCode():null;
    }

    protected String nvl(String s) {
        return s == null?"":s;
    }
}
